home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / dev / Oberon_Sources / OOP_in_Oberon-2 / GraphicElems0.mod < prev    next >
Text File  |  1993-01-13  |  3KB  |  68 lines

  1. MODULE GraphicElems0; (*HM Mar-25-92*)
  2. IMPORT OS, Texts0, Shapes0, GraphicFrames0, TextFrames0, Viewers0;
  3. TYPE
  4.         Element* = POINTER TO ElemDesc;
  5.         ElemDesc* = RECORD (Texts0.ElemDesc)
  6.                 orgX, orgY: INTEGER;
  7.                 graphic: Shapes0.Graphic;
  8.         END;
  9.         UpdateFrame = POINTER TO UpdateFrameDesc;
  10.         UpdateFrameDesc = RECORD (GraphicFrames0.FrameDesc)
  11.                 text: Texts0.Text;
  12.                 e: Element
  13.         END;
  14. VAR f: GraphicFrames0.Frame; (*reused within a text frame whenever a graphic element has to be redrawn*)
  15. PROCEDURE (e: Element) Copy* (): Texts0.Element;
  16.         VAR res: Element;
  17. BEGIN NEW(res); res^ := e^; res.graphic := e.graphic.Copy(); RETURN res
  18. END Copy;
  19. PROCEDURE (e: Element) Draw* (x, y: INTEGER);
  20. BEGIN
  21.         f.x := x; f.y := y; f.w := e.w; f.h := e.h; f.orgX := e.orgX; f.orgY := e.orgY; f.graphic := e.graphic;
  22.         f.Draw
  23. END Draw;
  24. PROCEDURE (e: Element) HandleMouse* (f: OS.Object; x, y: INTEGER);
  25.         VAR v: Viewers0.Viewer; menu: TextFrames0.Frame; cont: UpdateFrame; buttons: SET;
  26. BEGIN REPEAT OS.GetMouse(buttons, x, y) UNTIL buttons = {};
  27.         menu := TextFrames0.NewMenu("", "Viewers0.Close  Viewers0.Copy  GraphicElems0.Update");
  28.         NEW(cont); cont.graphic := e.graphic;
  29.         cont.orgX := e.orgX + 10; cont.orgY := e.orgY + 10;
  30.         cont.text := f(TextFrames0.Frame).text; cont.e := e;
  31.         v := Viewers0.New(menu, cont)
  32. END HandleMouse;
  33. PROCEDURE (e: Element) Load* (VAR r: OS.Rider);
  34. BEGIN e.Load^ (r);
  35.         r.ReadInt(e.orgX); r.ReadInt(e.orgY);
  36.         NEW(e.graphic); Shapes0.InitGraphic(e.graphic); e.graphic.Load(r)
  37. END Load;
  38. PROCEDURE (e: Element) Store* (VAR r: OS.Rider);
  39. BEGIN e.Store^ (r); r.WriteInt(e.orgX); r.WriteInt(e.orgY); e.graphic.Store(r)
  40. END Store;
  41. PROCEDURE Insert*;
  42.         VAR e: Element; f: TextFrames0.Frame;
  43. BEGIN
  44.         IF Viewers0.focus # NIL THEN f := Viewers0.focus(TextFrames0.Frame);
  45.                 IF (f # NIL) & (f.caret.pos >= 0) THEN
  46.                         NEW(e); e.w := 12; e.h := 12; e.dsc := 0; e.orgX := 0; e.orgY := 0;
  47.                         NEW(e.graphic); Shapes0.InitGraphic(e.graphic);
  48.                         f.text.SetPos(f.caret.pos); f.text.WriteElem(e)
  49.                 END
  50.         END
  51. END Insert;
  52. PROCEDURE Update*;
  53.         VAR v: Viewers0.Viewer; f: UpdateFrame; e: Element; m: Texts0.NotifyReplMsg; x, y: INTEGER; pos: LONGINT;
  54. BEGIN v := Viewers0.ViewerAt(TextFrames0.cmdFrame.y); f := v.cont(UpdateFrame);
  55.         e := f.e; pos := f.text.ElemPos(e);
  56.         IF pos < f.text.len THEN
  57.                 f.graphic.GetBox(x, y, e.w, e.h);
  58.                 e.graphic := f.graphic; e.orgX := - x ; e.orgY := - y;
  59.                 m.t := f.text; m.beg := pos; m.end := pos + 1; Viewers0.Broadcast(m)
  60.         END
  61. END Update;
  62. PROCEDURE Init;
  63.         VAR g: Shapes0.Graphic;
  64. BEGIN NEW(g); Shapes0.InitGraphic(g); f := GraphicFrames0.New(g)
  65. END Init;
  66. BEGIN Init
  67. END GraphicElems0.
  68.